import axios from 'axios';

import store from '../store';

function createInstance(){
    const instance=axios.create({
        baseURL:'http://127.0.0.1:8883',//http://127.0.0.1:8883
        timeout:5000
    })

    instance.interceptors.request.use(function (config){
        if(config.url.indexOf("/user/")==-1){
            config.headers['Authorization']=(store.state.token&&store.state.token.tokenn)||'';
        }

        return config;
    })
    instance.interceptors.response.use(function (response){
            if(response.status!=200){
                throw new Error("网络异常");
                return;
            }
       return response.data;
    })

    return instance
}

export default createInstance();